package com.hm.shopping.web.tourists;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hm.common.util.EncryptUtil.Base64;
import com.hm.common.annotation.WebClientRequestIntercept;
import com.hm.common.util.StringUtil;
import com.hm.shopping.auto.SystemEnvConfigProperties;
import com.hm.shopping.auto.su.BaseController;
import com.hm.shopping.auto.su.R.Uri;
import com.hm.shopping.auto.su.helper.HmSessionFactory;
import com.hm.shopping.service.GoodsIntroductionService;
import com.hm.shopping.service.ShopcartService;
import com.hm.shopping.vo.GoodsIntroductionVo;

import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2018年1月22日 上午10:46:52
 * @version 1.0
 * @describe
 */
@Slf4j
@Controller
@RequestMapping(Uri.PC + "/goods/introduction")
public class GoodsIntroductionController extends BaseController {

	@Autowired
	private ShopcartService shopcartService;
	
	@Autowired
	private GoodsIntroductionService goodsIntroductionService;
	
	@Autowired
	private SystemEnvConfigProperties systemEnvConfigProperties;

	@WebClientRequestIntercept(auth = false)
	@RequestMapping(value = "goodsIntroduction.do", method = RequestMethod.GET)
	public String goodsIntroduction(Model model, String goodsId) {
		if (StringUtil.isBlankOrNull(goodsId)) {
			return DATA_PAGE_NOT_FOUND;
		}
		GoodsIntroductionVo goodsIntroduction = goodsIntroductionService.getGoodsIntroduction(goodsId);
		log.info("加载商品介绍信息:" + goodsIntroduction.toString());
		model.addAttribute("goodsIntroduction", goodsIntroduction);//商品介绍
		model.addAttribute("guessLike", goodsIntroductionService.guessLikeGoodsList(goodsIntroduction.getClassificationCodes()));//猜你喜欢
		model.addAttribute("copyrightStatement", new String(Base64.decode(systemEnvConfigProperties.getFooterCopyrightStatementPC().toCharArray())));//版权信息
		try {
			model.addAttribute("shopcartGoodsCount", shopcartService.getShopcartGoodsCount(HmSessionFactory.currentUserIdString()));
		}catch(Exception e) {
			model.addAttribute("shopcartGoodsCount", shopcartService.getShopcartGoodsCount(null));
		}
		return "introduction";
	}
}
